//
//  WmcUnifiedNumberEx.swift
//  YPWatermarkCamera
//
//  Created by 赵新 on 2022/3/1.
//

import UIKit
import YPBedrock

extension YPUnifiedNumber {
    /// 转换成自适应Font
    var wmc_font: UIFont {
        let fontSize: CGFloat = .YP.Create(self)
        return fontSize.yp.uiFont
    }

    /// 计算与屏幕水平响应的适配值
    var wmc_autoHor: CGFloat {
        return wmc_ratioHor * Wmc_screenWidth
    }

    /// 计算与屏幕垂直响应的适配值
    var wmc_autoVer: CGFloat {
        return wmc_ratioVer * Wmc_screenHeight
    }

    /// 计算与屏幕水平比率
    var wmc_ratioHor: CGFloat {
        return wmc_ratio(Wmc_standardWidth)
    }

    /// 计算与屏幕垂直比率
    var wmc_ratioVer: CGFloat {
        return wmc_ratio(Wmc_standardHeight)
    }

    /// 计算与某个参考系的比率
    /// - Parameter reference: 参考系值
    /// - Returns: CGFloat
    func wmc_ratio(_ reference: YPUnifiedNumber) -> CGFloat {
        let ra = CGFloat.YP.Create(self) / CGFloat.YP.Create(reference)
        return ra
    }
    
    /// 根据屏幕宽度进行缩放的字体
    /// - Parameter weight: 字重
    func wmc_scaleFont(weight: YPBedrockFontWeight = .regular) -> UIFont {
        return wmc_autoHor.yp.uiFont(weight: weight)
    }
    
    /// 转换成自适应Font
    func wmc_font(weight: YPBedrockFontWeight = .regular) -> UIFont {
        let fontSize: CGFloat = .YP.Create(self)
        return fontSize.yp.uiFont(weight: weight)
    }
}

extension YPUnifiedNumber {
    /// 转换为时间字符串
    var wmc_secondsToTime: String {
        let time = Double.YP.Create(self)
        guard time >= 0 else { return "-/-" }
        var seconds: Double = 0
        var minutes: Double = 0
        if time > 60 {
            minutes = time / 60
            seconds = time - floor(minutes) * 60
        } else {
            seconds = time
        }
        let _minutes: Int = .init(minutes)
        let _seconds: Int = .init(seconds)
        let string = String(format: "%02d:%02d", _minutes, _seconds)
        return string
    }
}
